package com.ado.abyss.core.service.impl;

import java.util.List;

import com.ado.abyss.core.params.page.PageRequest;
import com.ado.abyss.core.params.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.ado.abyss.core.dal.model.SysLog;
import com.ado.abyss.core.manager.SysLogManager;
import com.ado.abyss.core.service.SysLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service(value = "sysLogService")
public class SysLogServiceImpl implements SysLogService{

	
	@Autowired
	@Qualifier(value = "sysLogManager")
	private SysLogManager sysLogManager ;

	@Override
	public boolean save(SysLog sysLog) {
		return sysLogManager.saveLog(sysLog);
	}

	@Override
	public boolean deleteLog(SysLog sysLog) {
		boolean flag = sysLogManager.deleteById(sysLog.getId()) ;
		return flag;
	}

	@Override
	public boolean deleteLogBatch(List<SysLog> sysLogs) {
		boolean flag = sysLogManager.saveLogBatch(sysLogs) ;
		return flag;
	}

	@Override
	public SysLog getById(Long id) {
		SysLog sysLog = sysLogManager.findById(id) ;
		return sysLog;
	}

	@Override
	public PageResult findPage(PageRequest pRequest) {
		PageHelper.startPage(pRequest.getPageNum(),pRequest.getPageSize()) ;
		List<SysLog> sysLogs = sysLogManager.findAll() ;
		PageInfo<SysLog> pageInfo = new PageInfo<>(sysLogs) ;
		PageResult pageResult = convertToResult(pageInfo) ;
		return pageResult;
	}

	private PageResult convertToResult(PageInfo<SysLog> pageInfo) {
		PageResult pageResult = new PageResult() ;
		pageResult.setPageNum(pageInfo.getPageNum());
		pageResult.setPageSize(pageInfo.getPageSize());
		pageResult.setTotalSize(pageInfo.getSize());
		pageResult.setTotalPages(pageInfo.getPages());
		pageResult.setContent(pageInfo.getList());
		return pageResult ;
	}
}
